﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using WomanMotion.WebApi.Infrastructure.DataBaseCommon;
using WomanMotion.WebApi.Model.Dtos.Classify;
using WomanMotion.WebApi.Model.Dtos.Team;
using WomanMotion.WebApi.Model.Dtos.Users;
using WomanMotion.WebApi.Model.Entitys;
using WomanMotion.WebApi.Repository.IRepository;
using WomanMotion.WebApi.Repository.Repository;
using WomanMotion.WebApi.Service.IService;

namespace WomanMotion.WebApi.Service.Service
{
    public class ClassifyService : BaseCRUDService<Classify, ClassifyVM, UpdateClassifyDTO, CreatedClassifyDTO>, IClassifyService
    {
        private readonly IClassifyRepository _classifyRepository;

        public ClassifyService(ILogger<ClassifyService> logger, IMapper mapper, IClassifyRepository classifyRepository, IHttpContextAccessor httpContext) : base(logger, mapper, classifyRepository, httpContext)
        {
            this._classifyRepository = classifyRepository;
        }

        /// <summary>
        /// 获取分类Tree数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<ClassifyTreeVM>> GetTreeListAsync()
        {
            var res = await this._classifyRepository.GetCommonListAsync<ClassifyTreeVM>(_classifyRepository.GetDB().Queryable<Classify>()

                .Select(m =>
            new ClassifyTreeVM()
            {
                id = m.Id,
                parentId = m.Parentid,
                value = m.Id,
                label = m.Name,
                Ifdisable = m.Ifdisable
            }).MergeTable().Where(m => m.Ifdisable == 1));
            return res;
        }
    }
}